package org.edu.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "FACULITY", catalog = "SCHOOL")
public class Faculity implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long faculity_id;
	private Set<Sciency> sciencies = new HashSet<>();
	private String faculity_code;
	private String faculity_name;

	@Id
	@GeneratedValue
	@Column(name = "FACULITY_ID")
	public Long getFaculity_id() {
		return faculity_id;
	}

	public void setFaculity_id(Long faculity_id) {
		this.faculity_id = faculity_id;
	}

	@OneToMany(targetEntity = Sciency.class, mappedBy = "faculity", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<Sciency> getSciencies() {
		return sciencies;
	}

	public void setSciencies(Set<Sciency> sciencies) {
		this.sciencies = sciencies;
	}

	@Column(name = "FACULITY_CODE")
	public String getFaculity_code() {
		return faculity_code;
	}

	public void setFaculity_code(String faculity_code) {
		this.faculity_code = faculity_code;
	}

	@Column(name = "FACULITY_NAME")
	public String getFaculity_name() {
		return faculity_name;
	}

	public void setFaculity_name(String faculity_name) {
		this.faculity_name = faculity_name;
	}

	public Faculity() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((faculity_code == null) ? 0 : faculity_code.hashCode());
		result = prime * result
				+ ((faculity_id == null) ? 0 : faculity_id.hashCode());
		result = prime * result
				+ ((faculity_name == null) ? 0 : faculity_name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Faculity other = (Faculity) obj;
		if (faculity_code == null) {
			if (other.faculity_code != null)
				return false;
		} else if (!faculity_code.equals(other.faculity_code))
			return false;
		if (faculity_id == null) {
			if (other.faculity_id != null)
				return false;
		} else if (!faculity_id.equals(other.faculity_id))
			return false;
		if (faculity_name == null) {
			if (other.faculity_name != null)
				return false;
		} else if (!faculity_name.equals(other.faculity_name))
			return false;
		return true;
	}

}
